package cn.chenfyuan.demoapplication.controller;

import javax.annotation.Resource;

import cn.chenfyuan.demoapplication.entity.Permission;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import cn.chenfyuan.demoapplication.service.PermissionService;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author linweijian
 * @since 2018-08-31
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {

	@Resource
	private PermissionService permissionService;

	@RequestMapping(value = "/", method = RequestMethod.GET)
	public ResponseEntity<?> queryPage(@RequestParam int pageNum, @RequestParam int pageSize, @ModelAttribute Permission vo) {
			Page<Permission> page = permissionService.selectPage(new Page<>(pageNum, pageSize), vo);
			return new ResponseEntity<>(page, HttpStatus.OK);

	}

	@RequestMapping(value = "/", method = RequestMethod.POST)
	public ResponseEntity<?> add(@RequestBody Permission vo) {
			return new ResponseEntity<>(permissionService.insert(vo),HttpStatus.OK);
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public ResponseEntity<?> delete(@PathVariable("id") String id) {
			return new ResponseEntity<>(permissionService.deleteById(id),HttpStatus.OK);

	}

	@RequestMapping(value = "/", method = RequestMethod.PUT)
	public ResponseEntity<?> update(@RequestBody Permission vo) {
			return new ResponseEntity<>(permissionService.updateById(vo),HttpStatus.OK);
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResponseEntity<?> get(@PathVariable("id") String id) {
	    return new ResponseEntity<>(permissionService.selectById(id),HttpStatus.OK);
	}


}

